# -*- coding: utf-8 -*-
import time
import machine
import dht
from machine import ADC, PWM, Pin, Timer
from machine import UART
from machine import Pin  #载入Pin模块
io = Pin(2, Pin.OUT)    # 在GPIO0上创建输出
io.on()

try:
    import ujson as json
except ImportError:
    import json

class Func():

    def send(self, text=''):
        self.mqtt_send(text)
    def mqtt_send(self, Data=''):
        pass



    # 回调处理
    def mqtt_receive(self, topic, rejson):
        print("mqtt", rejson )

        if 'type' in dict(rejson).keys():
            
            if rejson['type'] == 'post':
                io.off()
                uart = UART(1, 115200)
                number =  int(rejson["message"])
                uart.write( bytes([0xe0,number]) )
                self.send(  {'type':'post','message': rejson["message"] })
                io.on()
             
            if rejson['type'] == 'get':
                io.off()
                uart = UART(1, 115200)
                number =  int(rejson["message"])
                uart.write( bytes([0xe3,number]) )
                self.send(  {'type':'get','message': rejson["message"] })
                io.on()
        